bl_info = {
    "name": "Material Panel",
    "author": "Your Name",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "3D Viewport > Sidebar > Material",
    "description": "显示材质缩略图和名称",
    "category": "3D View",
}

import bpy
from .color_palette import export_classes as color_classes
from .material_utils import export_classes as material_classes
from .color_palette import load_preset_colors

# 合并所有类
all_classes = material_classes + color_classes

from .color_palette import export_properties as color_properties


# 合并所有属性
all_properties = color_properties
@bpy.app.handlers.persistent
def on_load_handler(dummy):
    """在场景加载完成后执行默认颜色初始化"""
    try:
        scene = bpy.context.scene
        if scene:
            load_preset_colors(scene)
    except Exception as e:
        print(f"Failed to load preset colors: {e}")
def register():
    # 注册所有类
    for cls in all_classes:
        bpy.utils.register_class(cls)
    
    # 注册场景属性
    for prop_name, prop_value in all_properties:
        setattr(bpy.types.Scene, prop_name, prop_value)
    # 添加加载后处理函数
    if on_load_handler not in bpy.app.handlers.load_post:
        bpy.app.handlers.load_post.append(on_load_handler)
def unregister():
    # 移除加载后处理函数
    if on_load_handler in bpy.app.handlers.load_post:
        bpy.app.handlers.load_post.remove(on_load_handler)
    # 注销场景属性
    for prop_name, _ in reversed(all_properties):
        delattr(bpy.types.Scene, prop_name)
    
    # 注销所有类(逆序)
    for cls in reversed(all_classes):
        bpy.utils.unregister_class(cls)
    if on_load_handler in bpy.app.handlers.load_post:
        bpy.app.handlers.load_post.remove(on_load_handler)
if __name__ == "__main__":
    register()